home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / PowerD / powerd / examples / timing.d < prev   
Text File  |  2002-10-28  |  1KB  |  59 lines

  1. MODULE 'dos/dos'
  2.  
  3. PROC main()
  4.   x:=9999
  5.   y:=1717
  6.   test(`x+y,     'Addition')
  7.   test(`y-x,     'Subtraction')
  8.   test(`x*y,     'Multiplication')
  9.   test(`x/y,     'Division')
  10.   test(`x | y,   'Bitwise OR')
  11.   test(`x & y,   'Bitwise AND')
  12.   test(`x=y,     'Equality')
  13.   test(`x<y,     'Less than')
  14.   test(`x<=y,    'Less than or equal')
  15.   test(`y:=1,    'Assignment of 1')
  16.   test(`y:=x,    'Assignment of x')
  17.   test(`y++,     'Increment')
  18.   test(`IF FALSE THEN y ELSE x, 'IF FALSE')
  19.   test(`IF TRUE THEN y ELSE x,  'IF TRUE')
  20.   test(`IF x THEN y ELSE x,     'IF x')
  21.   test(`fred(2), 'fred(2)')
  22. ENDPROC
  23.  
  24. CONST TICKS_PER_MINUTE=TICKS_PER_SECOND*60, LOTS_OF_TIMES=500000
  25.  
  26. DEF x, y, offset
  27.  
  28. PROC fred(n)
  29.   DEF i
  30.   i:=n+x
  31. ENDPROC
  32.  
  33. /* Repeat evaluation of an expression */
  34. PROC repeat(exp)
  35.   DEF i
  36.   FOR i:=0 TO LOTS_OF_TIMES
  37.     Eval(exp) /* Evaluate the expresssion */
  38.   ENDFOR
  39. ENDPROC
  40.  
  41. /* Time an expression, and set-up offset if not done already */
  42. PROC test(exp, message)
  43.   DEF t
  44.   IF offset=0 THEN offset:=time(`0)  /* Calculate offset */
  45.   t:=time(exp)
  46.   PrintF('\s:\t\d ticks\n', message, t-offset)    
  47. ENDPROC
  48.  
  49. /* Time the repeated calls, and calculate number of ticks */
  50. PROC time(x)(LONG)
  51.   DEF ds1:DateStamp, ds2:DateStamp
  52.   Forbid()
  53.   DateStamp(ds1)
  54.   repeat(x)
  55.   DateStamp(ds2)
  56.   Permit()
  57.   IF CtrlC() THEN Exit(1)
  58. ENDPROC ((ds2.Minute-ds1.Minute)*TICKS_PER_MINUTE)+ds2.Tick-ds1.Tick
  59.